﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ReferralTracker.Data.Repositories;
using ReferralTracker.Data.Contexts;
using ReferralTracker.BusinessObjects.Infrastructure;
using ReferralTracker.Data.Entities;
using ReferralTracker.Data.Lookups;

namespace ReferralTracker.BusinessObjects {
    public class Authentication : BusinessObject {

        public Authentication() : base() {}
        public Authentication(ISession session) : base(session) {}

        public bool VerifyUser(string email, string password) {
            var userRepo = new UserRepository(_context);
            var user = userRepo.FindByCredentials(email, password);

            return (user != null);
        }

        public void SignIn(User user) {
            switch (user.IdUserType) {
                case UserType.User:
                    user.UserDetail.LastLoginDate = DateTime.Now;
                    break;
            }
            SaveChanges();
        }
    }
}
